#include "xml.h"
#include "label.h"
#include "lineedit.h"

#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>

#include <QString>
#include <QLabel>
#include <QGridLayout>
#include <QLineEdit>
#include <QComboBox>
#include <QRadioButton>
#include <QTextEdit>
#include <QCheckBox>
#include <QScrollBar>
#include <QButtonGroup>
#include <QIntValidator>
#include <QValidator>
#include <QFrame>
#include <QObject>
#include <QFile>
#include <QFileDialog>
#include <QDialog>
#include <QDomDocument>
#include <QDomProcessingInstruction>
#include <QTextStream>
#include <QFileInfo>
#include <QToolButton>
Xml::Xml(QGridLayout* widget)
{
    str_soft_hp = "";
    createPageXml(widget);
}

Xml::~Xml()
{

}

void Xml::createPageXml(QGridLayout* widget)
{
    QString vertical_text = QString("QScrollBar:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,0,0,0%);"
                                    "margin:0px,0px,0px,0px;"
                                    "padding-top:9px;"
                                    "padding-bottom:9px;"
                                    "}"
                                    "QScrollBar::handle:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,25%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::handle:vertical:hover"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,60%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::add-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_normal.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_normal.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_pressed.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_pressed.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
                                    "{"
                                    "background:rgba(77,0,0,10%);"
                                    "border-radius:4px;"
                                    "}");

    //buju-1
    QPixmap plinfo;
    plinfo.load("/usr/share/cpktransform/images/btn_1.png");
    Label* linfo = new Label("基本信息(必填)", plinfo);
    linfo->setPixmap(plinfo);
    linfo->setFrameStyle(QFrame::NoFrame);

    QLabel* occupying2 = new QLabel();
    occupying2->setFixedHeight(10);
    occupying2->setStyleSheet("border:0px;");
    gbox_info = new QGridLayout();
    QLabel* soft_name_en = new QLabel("软件名称：");
    soft_name_en->setStyleSheet("QLabel{border-width:0px;}");
    soft_name_en->setFixedWidth(70);
    QLabel* soft_name = new QLabel("通用名称：");
    soft_name->setStyleSheet("QLabel{border-width:0px;}");
    soft_name->setFixedWidth(70);

    sname_en = new CLineEdit();
    sname_en->setPlaceholderText("Enter the application name, required");
    sname_en->setTextMargins(0,0,25,0);
    sname_en->setFixedWidth(200);
    sname_en->setFixedHeight(27);
    sname_en->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    QFrame* frame = new QFrame(sname_en);
    frame->setGeometry(QRect(1,1,25,25));
    frame->setObjectName("myCollectorframe");
    frame->setStyleSheet(QString("QFrame#myCollectorframe{border-image:url(/usr/share/cpktransform/images/en.png)}"));
    // 鼠标在上面的效果
    //frame->setCursor(Qt::PointingHandCursor);
    sname_en->setTextMargins(25,-1,-1,-1);

    sname = new CLineEdit();
    sname->setPlaceholderText("输入应用名称，必填项");
    sname->setTextMargins(0,0,25,0);
    sname->setFixedWidth(200);
    sname->setFixedHeight(27);
    sname->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    QFrame* frame_zh = new QFrame(sname);
    frame_zh->setGeometry(QRect(1,1,25,25));
    frame_zh->setObjectName("myCollectorframe2");
    frame_zh->setStyleSheet(QString("QFrame#myCollectorframe2{border-image:url(/usr/share/cpktransform/images/zh.png)}"));
    // 鼠标在上面的效果
    //frame->setCursor(Qt::PointingHandCursor);
    sname->setTextMargins(25,-1,-1,-1);

    QLabel* soft_category = new QLabel("软件类别：");
    soft_category->setStyleSheet("QLabel{border-width:0px;}");
    soft_category->setFixedWidth(70);
    scategory = new QComboBox();
    scategory->setFixedWidth(200);
    scategory->setFixedHeight(27);
    QString down_text = QString("QComboBox::down-arrow {image: url(/usr/share/cpktransform/images/down.png);} "
                                "QComboBox::drop-down "
                                "{subcontrol-origin: "
                                "padding; subcontrol-position: top right; width: 20px;border-left-width: 1px;"
                                "border-left-color: darkgray;border-left-style: solid;"
                                "border-top-right-radius: 3px;"
                                " border-bottom-right-radius: 3px;}"
                                "QComboBox{background-color:rgb(255,255,240);"
                                "color:rgb(105,105,105);border-image:none; "
                                "border:1px solid gray; border-radius:2px};");
    scategory->setStyleSheet(down_text);
    scategory->addItem("办公");
    scategory->addItem("应用");
    scategory->addItem("网络");
    scategory->addItem("通讯");
    scategory->addItem("图像");
    scategory->addItem("影音");
    scategory->addItem("安全");
    scategory->addItem("系统");
    scategory->addItem("开发");
    scategory->addItem("其他");
    scategory->setCurrentIndex(1); //软件类别默认选择“应用”
    //add text to the widget

    QLabel* soft_version = new QLabel("软件版本：");
    soft_version->setStyleSheet("QLabel{border-width:0px;}");
    QHBoxLayout* hbox_version = new QHBoxLayout();
    QLabel* flag = new QLabel("V");
    QLabel* flag_1 = new QLabel(".");
    flag_1->setStyleSheet("QLabel{border-width:0px;}");
    QLabel* flag_2 = new QLabel(".");
    flag_2->setStyleSheet("QLabel{border-width:0px;}");
    l_1 = new CLineEdit();
    l_2 = new CLineEdit();
    l_3 = new CLineEdit();
    QValidator *validator=new QIntValidator(0,100,widget);
    l_1->setValidator(validator);
    l_2->setValidator(validator);
    l_3->setValidator(validator);

    flag->setFixedWidth(10);
    flag_1->setFixedWidth(5);
    flag_2->setFixedWidth(5);
    l_1->setFixedWidth(50);
    l_2->setFixedWidth(50);
    l_3->setFixedWidth(50);
    l_1->setFixedHeight(27);
    l_2->setFixedHeight(27);
    l_3->setFixedHeight(27);
    l_1->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    l_2->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    l_3->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");

    hbox_version->addWidget(l_1);
    hbox_version->addWidget(flag_1);
    hbox_version->addWidget(l_2);
    hbox_version->addWidget(flag_2);
    hbox_version->addWidget(l_3);
    hbox_version->setAlignment(l_3,Qt::AlignLeft);

    QLabel* soft_arch = new QLabel("软件架构：");
    soft_arch->setStyleSheet("QLabel{border-width:0px;}");
    larch = new CLineEdit();
    larch->setTextMargins(0,0,25,0);
    larch->setFixedWidth(200);
    larch->setFixedHeight(27);
    larch->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");

    QLabel* soft_dependence = new QLabel("CCF依赖 ：");
    soft_dependence->setStyleSheet("QLabel{border-width:0px;}");
    sdenpendence = new QComboBox();
    sdenpendence->setFixedWidth(200);
    sdenpendence->setFixedHeight(27);
    sdenpendence->setStyleSheet(down_text);

    sdenpendence->addItem("CCF1(>=1.0)");
    sdenpendence->addItem("CCF1(>=2.0)");
    sdenpendence->setCurrentIndex(0);
    QLabel* soft_dense = new QLabel("软件密级：");
    soft_dense->setStyleSheet("QLabel{border-width:0px;}");
    sdense = new QComboBox();
    sdense->setFixedWidth(200);
    sdense->setFixedHeight(27);
    sdense->setStyleSheet(down_text);
    sdense->addItem("公开");
    sdense->addItem("秘密");
    sdense->addItem("机密");
    sdense->addItem("绝密");
    sdense->addItem("其他");
    sdense->setCurrentIndex(0);

    QLabel* lexecute = new QLabel("执行语句：");
    lexecute->setStyleSheet("QLabel{border-width:0px;}");
    lExec = new CLineEdit();
    lExec->setPlaceholderText("主程序启动命令，必填项");
    lExec->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    lExec->setFixedWidth(200);
    lExec->setFixedHeight(27);

    soft_name->setFixedWidth(70);
    soft_name->setFixedHeight(27);
    soft_category->setFixedWidth(70);
    soft_category->setFixedHeight(27);
    soft_version->setFixedWidth(70);
    soft_version->setFixedHeight(27);
    soft_dependence->setFixedWidth(70);
    soft_dependence->setFixedHeight(27);
    soft_dense->setFixedWidth(70);
    soft_dense->setFixedHeight(27);
    gbox_info->addWidget(soft_name_en,0,0,1,1);
    gbox_info->addWidget(sname_en,0,1,1,1);
    gbox_info->addWidget(soft_name, 1,0,1,1);
    gbox_info->addWidget(sname,1,1,1,1);
    gbox_info->addWidget(soft_category,2,0,1,1);
    gbox_info->addWidget(scategory,2,1,1,1);
    gbox_info->addWidget(soft_version,3,0,1,1);
    gbox_info->addLayout(hbox_version,3,1,1,1);
    gbox_info->addWidget(soft_arch,4,0,1,1);
    gbox_info->addWidget(larch,4,1,1,1);
    gbox_info->addWidget(soft_dependence,5,0,1,1);
    gbox_info->addWidget(sdenpendence,5,1,1,1);
    gbox_info->addWidget(soft_dense,6,0,1,1);
    gbox_info->addWidget(sdense,6,1,1,1);
    gbox_info->addWidget(lexecute, 7,0,1,1);
    //gbox_info->addLayout(hExec,7,1,1,1);
    gbox_info->setAlignment(soft_name,Qt::AlignLeft);

    QWidget* s_info = new QWidget;
    s_info->setFixedSize(470,280);
    s_info->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:2px");//mencius
    s_info->setLayout(gbox_info);

    widget->addWidget(occupying2,0,0,1,1);
    widget->addWidget(linfo,1,0,1,1);
    widget->addWidget(s_info,2,0,1,1);
    widget->setAlignment(linfo,Qt::AlignTop);
    widget->setAlignment(gbox_info,Qt::AlignLeft);


    //buju-2
    QPixmap pdetails;
    pdetails.load("/usr/share/cpktransform/images/btn_2.png");
    Label* details = new Label("应用详情",pdetails);
    details->setPixmap(pdetails);
    QGridLayout* gbox_details = new QGridLayout();
    QLabel* soft_sdesc = new QLabel("  短描述：");
    soft_sdesc->setFixedWidth(70);
    soft_sdesc->setStyleSheet("QLabel{border-width:0px;}");
    lsdesc = new QLineEdit();
    lsdesc->setTextMargins(0,0,25,0);
    lsdesc->setFixedWidth(365);
    lsdesc->setFixedHeight(27);
    lsdesc->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    QFrame* frame_ls = new QFrame(lsdesc);
    frame_ls->setGeometry(QRect(1,1,25,25));
    frame_ls->setObjectName("myCollectorframe");
    frame_ls->setStyleSheet(QString("QFrame#myCollectorframe{border-image:url(/usr/share/cpktransform/images/zh.png)}"));
    // 鼠标在上面的效果
    //frame->setCursor(Qt::PointingHandCursor);
    lsdesc->setTextMargins(25,-1,-1,-1);

    lsdesc_en = new QLineEdit();
    lsdesc_en->setTextMargins(0,0,25,0);
    lsdesc_en->setFixedHeight(27);
    lsdesc_en->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    QFrame* frame_en = new QFrame(lsdesc_en);
    frame_en->setGeometry(QRect(1,1,25,25));
    frame_en->setObjectName("myCollectorframe_");
    frame_en->setStyleSheet(QString("QFrame#myCollectorframe_{border-image:url(/usr/share/cpktransform/images/en.png)}"));
    lsdesc_en->setFixedWidth(365);
    lsdesc_en->setTextMargins(25,-1,-1,-1);

    QLabel* occupying3= new QLabel("");
    occupying3->setFixedWidth(60);
    occupying3->setStyleSheet("QLabel{border-width:0px;}");
    QLabel* soft_ldesc = new QLabel(" 长描述：");
    //    soft_ldesc->setFixedWidth(70);
    soft_ldesc->setStyleSheet("QLabel{border-width:0px;font-family:'URW Chancery L'; font-size:16px;}");
    //    soft_ldesc->setStyleSheet("QLabel{border-width:0px;font-family:'方正魏碑_GBK'; font-size:16px;}");

    tldesc = new Textedit();
    tldesc->setStyleSheet("QTextEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px;padding-left:25}");
    tldesc->verticalScrollBar()->setStyleSheet(vertical_text );

    //国旗图标
    QFrame* frame_l = new QFrame(tldesc);
    frame_l->setGeometry(QRect(1,1,25,25));
    frame_l->setObjectName("_myCollectorframe");
    frame_l->setStyleSheet(QString("QFrame#_myCollectorframe{border-image:url(/usr/share/cpktransform/images/zh.png)}"));
    // 鼠标在上面的效果
    //frame->setCursor(Qt::PointingHandCursor);

    tldesc->setFixedWidth(365);
    tldesc->setFixedHeight(80);
    tldesc->ensureCursorVisible();//光标可见

    tldesc_en = new QTextEdit();
    tldesc_en->setStyleSheet("QTextEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px;padding-left:25}");

    QLabel* occupying4= new QLabel("");
    occupying4->setFixedWidth(60);
    occupying4->setStyleSheet("QLabel{border-width:0px;}");
    //英期图标
    QFrame* frame_enl = new QFrame(tldesc_en);
    frame_enl->setGeometry(QRect(1,1,25,25));
    frame_enl->setObjectName("myCollectorframe_l");
    frame_enl->setStyleSheet(QString("QFrame#myCollectorframe_l{border-image:url(/usr/share/cpktransform/images/en.png)}"));

    tldesc_en->setFixedWidth(365);
    tldesc_en->setFixedHeight(80);
    tldesc_en->verticalScrollBar()->setStyleSheet(vertical_text);

    gbox_details->addWidget(soft_sdesc,0,0,1,1);
    gbox_details->addWidget(lsdesc,0,1,1,1);
    gbox_details->addWidget(occupying3,1,0,1,1);
    gbox_details->addWidget(lsdesc_en,1,1,1,1);
    gbox_details->addWidget(soft_ldesc,2,0,1,1);
    gbox_details->addWidget(tldesc,2,1,1,1);
    gbox_details->addWidget(occupying4,3,0,1,1);
    gbox_details->addWidget(tldesc_en,3,1,1,1);
    gbox_details->setAlignment(soft_ldesc, Qt::AlignTop | Qt::AlignRight);
    gbox_details->setAlignment(soft_sdesc, Qt::AlignRight);

    QWidget* s_details = new QWidget;
    s_details->setFixedSize(470,260);
    s_details->setLayout(gbox_details);
    s_details->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:2px");//mencius

    QLabel* occupying_0 = new QLabel("");
    occupying_0->setFixedHeight(10);
    occupying_0->setStyleSheet("border:0px;");
    widget->setAlignment(details,Qt::AlignTop);
    widget->addWidget(occupying_0,3,0,1,1);
    widget->addWidget(details,4,0,1,1);
    widget->addWidget(s_details,5,0,1,1);
    widget->setAlignment(gbox_details,Qt::AlignLeft);

    //buju-3
    QPixmap ppermission;
    ppermission.load("/usr/share/cpktransform/images/btn_3.png");
    Label* permission = new Label("应用权限",ppermission);
    permission->setPixmap(ppermission);
    root_user = new QCheckBox("需要ROOT权限");
    root_user->setChecked(false);
    root_user->setStyleSheet("QCheckBox{border-width:0px;}");
    sudo_user = new QCheckBox("需要SUDO权限");
    sudo_user->setChecked(false);
    sudo_user->setStyleSheet("QCheckBox{border-width:0px;}");
    ipc_user = new QCheckBox("使用IPC");
    ipc_user->setChecked(false);
    ipc_user->setStyleSheet("QCheckBox{border-width:0px;}");
    s_n_access = new QCheckBox("获取网络状态");
    s_n_access->setChecked(false);
    s_n_access->setStyleSheet("QCheckBox{border-width:0px;}");
    network_access = new QCheckBox("访问网络");
    network_access->setChecked(false);
    network_access->setStyleSheet("QCheckBox{border-width:0px;}");
    xorg_access = new QCheckBox("访问底层图形显示");
    xorg_access->setChecked(false);
    xorg_access->setStyleSheet("QCheckBox{border-width:0px;}");
    manager_user = new QCheckBox("用户管理");
    manager_user->setChecked(false);
    manager_user->setStyleSheet("QCheckBox{border-width:0px;}");
    m_g_user = new QCheckBox("用户组管理");
    m_g_user->setChecked(false);
    m_g_user->setStyleSheet("QCheckBox{border-width:0px;}");
    variable_system = new QCheckBox("系统变量管理");
    variable_system->setChecked(false);
    variable_system->setStyleSheet("QCheckBox{border-width:0px;}");
    manager_device = new QCheckBox("设备管理");
    manager_device->setChecked(false);
    manager_device->setStyleSheet("QCheckBox{border-width:0px;}");
    m_i_open = new QCheckBox("绑定输入法");
    m_i_open->setChecked(false);
    m_i_open->setStyleSheet("QCheckBox{border-width:0px;}");
    manager_app = new QCheckBox("应用管理");
    manager_app->setChecked(false);
    manager_app->setStyleSheet("QCheckBox{border-width:0px;}");
    setting_system = new QCheckBox("修改系统配置");
    setting_system->setChecked(false);
    setting_system->setStyleSheet("QCheckBox{border-width:0px;}");
    conf_change = new QCheckBox("改变配置");
    conf_change->setChecked(false);
    conf_change->setStyleSheet("QCheckBox{border-width:0px;}");
    c_a_c = new QCheckBox("清除应用缓存");
    c_a_c->setChecked(false);
    c_a_c->setStyleSheet("QCheckBox{border-width:0px;}");
    d_u_a_c = new QCheckBox("清除用户数据");
    d_u_a_c->setChecked(false);
    d_u_a_c->setStyleSheet("QCheckBox{border-width:0px;}");
    underly_access = new QCheckBox("底层访问权限");
    underly_access->setChecked(false);
    underly_access->setStyleSheet("QCheckBox{border-width:0px;}");
    f_c_d = new QCheckBox("删除缓存文件");
    f_c_d->setChecked(false);
    f_c_d->setStyleSheet("QCheckBox{border-width:0px;}");
    diagnostic = new QCheckBox("应用诊断");
    diagnostic->setChecked(false);
    diagnostic->setStyleSheet("QCheckBox{border-width:0px;}");
    dump = new QCheckBox("转存系统信息");
    dump->setChecked(false);
    dump->setStyleSheet("QCheckBox{border-width:0px;}");
    a_d_c = new QCheckBox("修改默认程序");
    a_d_c->setChecked(false);
    a_d_c->setStyleSheet("QCheckBox{border-width:0px;}");
    m_s_c = new QCheckBox("修改开始菜单");
    m_s_c->setChecked(false);
    m_s_c->setStyleSheet("QCheckBox{border-width:0px;}");
    b_t_c = new QCheckBox("修改任务栏");
    b_t_c->setChecked(false);
    b_t_c->setStyleSheet("QCheckBox{border-width:0px;}");
    tasks_get = new QCheckBox("获取任务信息");
    tasks_get->setChecked(false);
    tasks_get->setStyleSheet("QCheckBox{border-width:0px;}");
    search_global = new QCheckBox("允许全局搜索");
    search_global->setChecked(false);
    search_global->setStyleSheet("QCheckBox{border-width:0px;}");
    p_b_k = new QCheckBox("结束后台进程");
    p_b_k->setChecked(false);
    p_b_k->setStyleSheet("QCheckBox{border-width:0px;}");
    clear_master = new QCheckBox("软格式化");
    clear_master->setChecked(false);
    clear_master->setStyleSheet("QCheckBox{border-width:0px;}");
    s_a_m = new QCheckBox("修改声音设置");
    s_a_m->setChecked(false);
    s_a_m->setStyleSheet("QCheckBox{border-width:0px;}");
    f_f_m = new QCheckBox("格式化文件系统");
    f_f_m->setChecked(false);
    f_f_m->setStyleSheet("QCheckBox{border-width:0px;}");
    f_u_m = new QCheckBox("挂载文件系统");
    f_u_m->setChecked(false);
    f_u_m->setStyleSheet("QCheckBox{border-width:0px;}");
    b_f_r = new QCheckBox("屏幕截图");
    b_f_r->setChecked(false);
    b_f_r->setStyleSheet("QCheckBox{border-width:0px;}");
    s_i_r = new QCheckBox("读取键盘输入状态");
    s_i_r->setChecked(false);
    s_i_r->setStyleSheet("QCheckBox{border-width:0px;}");
    logs_read = new QCheckBox("读取系统日志");
    logs_read->setChecked(false);
    logs_read->setStyleSheet("QCheckBox{border-width:0px;}");
    reboot = new QCheckBox("重启设备");
    reboot->setChecked(false);
    reboot->setStyleSheet("QCheckBox{border-width:0px;}");
    c_b_r= new QCheckBox("开机自动允许");
    c_b_r->setChecked(false);
    c_b_r->setStyleSheet("QCheckBox{border-width:0px;}");
    l_p_s = new QCheckBox("设置进程限制");
    l_p_s->setChecked(false);
    l_p_s->setStyleSheet("QCheckBox{border-width:0px;}");
    time_set = new QCheckBox("设置系统时间");
    time_set->setChecked(false);
    time_set->setStyleSheet("QCheckBox{border-width:0px;}");
    z_t_s = new QCheckBox("设置系统时区");
    z_t_s->setChecked(false);
    z_t_s->setStyleSheet("QCheckBox{border-width:0px;}");
    credentials_use = new QCheckBox("使用证书");
    credentials_use->setChecked(false);
    credentials_use->setStyleSheet("QCheckBox{border-width:0px;}");
    h_b_c = new QCheckBox("修改浏览器主页");
    h_b_c->setChecked(false);
    h_b_c->setStyleSheet("QCheckBox{border-width:0px;}");
    b_h_r = new QCheckBox("读取收藏夹和历史记录");
    b_h_r->setChecked(false);
    b_h_r->setStyleSheet("QCheckBox{border-width:0px;}");
    b_h_w = new QCheckBox("写入收藏夹和历史记录");
    b_h_w->setChecked(false);
    b_h_w->setStyleSheet("QCheckBox{border-width:0px;}");
    s_w_a = new QCheckBox("获取WiFi状态");
    s_w_a->setChecked(false);
    s_w_a->setStyleSheet("QCheckBox{border-width:0px;}");
    s_w_c = new QCheckBox("改变WiFi状态");
    s_w_c->setChecked(false);
    s_w_c->setStyleSheet("QCheckBox{border-width:0px;}");
    bluetooth = new QCheckBox("使用蓝牙");
    bluetooth->setChecked(false);
    bluetooth->setStyleSheet("QCheckBox{border-width:0px;}");
    manager_bluetooth =  new QCheckBox("蓝牙管理");
    manager_bluetooth->setChecked(false);
    manager_bluetooth->setStyleSheet("QCheckBox{border-width:0px;}");
    power_device = new QCheckBox("电源管理");
    power_device->setChecked(false);
    power_device->setStyleSheet("QCheckBox{border-width:0px;}");
    QGridLayout* gbox_permission = new QGridLayout;
    gbox_permission->addWidget(root_user,0,0,1,1);
    gbox_permission->addWidget(sudo_user,0,1,1,1);
    gbox_permission->addWidget(ipc_user,0,2,1,1);
    gbox_permission->addWidget(s_n_access,1,0,1,1);
    gbox_permission->addWidget(network_access,1,1,1,1);
    gbox_permission->addWidget(xorg_access,1,2,1,1);
    gbox_permission->addWidget(manager_user,2,0,1,1);
    gbox_permission->addWidget(m_g_user,2,1,1,1);
    gbox_permission->addWidget(variable_system,2,2,1,1);
    gbox_permission->addWidget(manager_device,3,0,1,1);
    gbox_permission->addWidget(m_i_open,3,1,1,1);
    gbox_permission->addWidget(manager_app,3,2,1,1);
    gbox_permission->addWidget(setting_system,4,0,1,1);
    gbox_permission->addWidget(conf_change,4,1,1,1);
    gbox_permission->addWidget(c_a_c,4,2,1,1);
    gbox_permission->addWidget(d_u_a_c,5,0,1,1);
    gbox_permission->addWidget(underly_access,5,1,1,1);
    gbox_permission->addWidget(f_c_d,5,2,1,1);
    gbox_permission->addWidget(diagnostic,6,0,1,1);
    gbox_permission->addWidget(dump,6,1,1,1);
    gbox_permission->addWidget(a_d_c,6,2,1,1);
    gbox_permission->addWidget(m_s_c,7,0,1,1);
    gbox_permission->addWidget(b_t_c,7,1,1,1);
    gbox_permission->addWidget(tasks_get,7,2,1,1);
    gbox_permission->addWidget(search_global,8,0,1,1);
    gbox_permission->addWidget(p_b_k,8,1,1,1);
    gbox_permission->addWidget(clear_master,8,2,1,1);
    gbox_permission->addWidget(s_a_m,9,0,1,1);
    gbox_permission->addWidget(f_f_m,9,1,1,1);
    gbox_permission->addWidget(f_u_m,9,2,1,1);
    gbox_permission->addWidget(b_f_r,10,0,1,1);
    gbox_permission->addWidget(s_i_r,10,1,1,1);
    gbox_permission->addWidget(reboot,10,2,1,1);
    gbox_permission->addWidget(c_b_r,11,0,1,1);
    gbox_permission->addWidget(logs_read,11,1,1,1);
    gbox_permission->addWidget(l_p_s,11,2,1,1);
    gbox_permission->addWidget(time_set,12,0,1,1);
    gbox_permission->addWidget(z_t_s,12,1,1,1);
    gbox_permission->addWidget(credentials_use,12,2,1,1);
    gbox_permission->addWidget(h_b_c,13,0,1,1);
    gbox_permission->addWidget(b_h_r,13,1,1,1);
    gbox_permission->addWidget(b_h_w,13,2,1,1);
    gbox_permission->addWidget(s_w_a,14,0,1,1);
    gbox_permission->addWidget(s_w_c,14,1,1,1);
    gbox_permission->addWidget(bluetooth,14,2,1,1);
    gbox_permission->addWidget(manager_bluetooth,15,0,1,1);
    gbox_permission->addWidget(power_device,15,1,1,1);

    QWidget* s_permission = new QWidget;
    s_permission->setFixedSize(470,400);
    s_permission->setLayout(gbox_permission);
    s_permission->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:2px");//mencius

    QLabel* occupying_1 = new QLabel("");
    occupying_1->setFixedHeight(10);
    occupying_1->setStyleSheet("border:0px;");
    widget->addWidget(occupying_1,6,0,1,1);
    widget->addWidget(permission,7,0,1,1);
    widget->addWidget(s_permission,8,0,1,1);
    widget->setAlignment(gbox_permission,Qt::AlignLeft);

    //buju-4
    QPixmap pauthor;
    pauthor.load("/usr/share/cpktransform/images/btn_4.png");
    Label* author = new Label("作者信息",pauthor);
    author->setPixmap(pauthor);
    QGridLayout* gbox_author = new QGridLayout();
    QLabel* a_type = new QLabel("作者类型：");
    a_type->setStyleSheet("QLabel{border-width:0px;}");
    QHBoxLayout* at = new QHBoxLayout();
    r_enterprise = new QRadioButton();
    r_enterprise->setText("企业开发者");
    r_individual = new QRadioButton();
    r_individual->setText("个人开发者");
    r_enterprise->setChecked(true);
    at->addWidget(r_enterprise);
    at->addWidget(r_individual);
    at->setAlignment(r_individual,Qt::AlignLeft);
    r_enterprise->setFixedWidth(120);
    r_enterprise->setStyleSheet("QRadioButton{border-width:0px;}");
    r_individual->setStyleSheet("QRadioButton{border-width:0px;}");

    QLabel* a_name = new QLabel("作者名称：");
    a_name->setStyleSheet("QLabel{border-width:0px;}");
    l_name = new QLineEdit();
    QLabel* a_tel = new QLabel("联系电话：");
    a_tel->setStyleSheet("QLabel{border-width:0px;}");
    l_tel = new QLineEdit();
    QLabel* a_pg = new QLabel("主        页：");
    l_pg = new QLineEdit();
    a_pg->setStyleSheet("QLabel{border-width:0px;}");
    QLabel* a_email = new QLabel("电子邮箱：");
    l_email = new QLineEdit();
    a_email->setStyleSheet("QLabel{border-width:0px;}");
    QLabel* a_desc = new QLabel("打包描述：");
    a_desc->setStyleSheet("QLabel{border-width:0px;}");
    l_desc = new QLineEdit();
    l_desc->setTextMargins(0,0,25,0);
    l_desc->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    QFrame* frame_1 = new QFrame(l_desc);
    frame_1->setGeometry(QRect(1,1,25,25));
    frame_1->setObjectName("myCollectorframe_");
    QString s_zh = QString("QFrame#myCollectorframe_{border-image:url(/usr/share/cpktransform/images/zh.png)}" );
    frame_1->setStyleSheet(s_zh);
    l_desc->setTextMargins(25,-1,-1,-1);

    l_desc_en = new QLineEdit();
    l_desc_en->setTextMargins(0,0,25,0);
    l_desc_en->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    QFrame* frame_2 = new QFrame(l_desc_en);
    frame_2->setGeometry(QRect(1,1,25,25));
    frame_2->setObjectName("myCollectorframe_");
    QString s = QString("QFrame#myCollectorframe_{border-image:url(/usr/share/cpktransform/images/en.png)}");
    frame_2->setStyleSheet(s);
    l_desc_en->setTextMargins(25,-1,-1,-1);

    l_name->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    l_tel->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    l_pg->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    l_email->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    //    a_type->setFixedWidth(60);
    //    a_name->setFixedWidth(60);
    //    a_email->setFixedWidth(60);
    //    a_desc->setFixedWidth(60);
    l_name->setFixedWidth(340);
    l_name->setFixedHeight(27);
    l_tel->setFixedWidth(340);
    l_tel->setFixedHeight(27);
    l_pg->setFixedWidth(340);
    l_pg->setFixedHeight(27);
    l_email->setFixedWidth(340);
    l_email->setFixedHeight(27);
    l_desc->setFixedWidth(340);
    l_desc->setFixedHeight(27);
    l_desc_en->setFixedWidth(340);
    l_desc_en->setFixedHeight(27);
    gbox_author->addWidget(a_type,0,0,1,1);
    gbox_author->addLayout(at,0,1,1,1);
    gbox_author->addWidget(a_name,1,0,1,1);
    gbox_author->addWidget(l_name,1,1,1,1);
    gbox_author->addWidget(a_tel,2,0,1,1);
    gbox_author->addWidget(l_tel,2,1,1,1);
    gbox_author->addWidget(a_pg,3,0,1,1);
    gbox_author->addWidget(l_pg,3,1,1,1);
    gbox_author->addWidget(a_email,4,0,1,1);
    gbox_author->addWidget(l_email,4,1,1,1);
    gbox_author->addWidget(a_desc,5,0,1,1);
    gbox_author->addWidget(l_desc,5,1,1,1);
    gbox_author->addWidget(l_desc_en,6,1,1,1);

    QWidget* s_author = new QWidget;
    s_author->setFixedSize(470,250);
    s_author->setLayout(gbox_author);
    s_author->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:2px");//mencius

    QLabel* occupying_2 = new QLabel("");
    occupying_2->setFixedHeight(10);
    occupying_2->setStyleSheet("border:0px;");
    widget->addWidget(occupying_2,9,0,1,1);
    widget->addWidget(author,10,0,1,1);
    widget->addWidget(s_author,11,0,1,1);
    widget->setAlignment(gbox_author,Qt::AlignLeft);

    //buju-5
    QPixmap pother;
    pother.load("/usr/share/cpktransform/images/btn_5.png");
    Label* sother = new Label("其他信息",pother);
    sother->setPixmap(pother);
    gbox_other = new QGridLayout();
    QLabel* is_desktop = new QLabel("是否桌面应用：");
    is_desktop->setStyleSheet("QLabel{border-width:0px;}");
    QHBoxLayout* hIsD = new QHBoxLayout();

    r_isDesktop = new QRadioButton();
    r_isDesktop->setText("是");
    r_isNoDesktop = new QRadioButton();
    r_isNoDesktop->setText("否");
    r_isDesktop->setChecked(true);
    r_isDesktop->setStyleSheet("QRadioButton{border-width:0px;}");
    r_isNoDesktop->setStyleSheet("QRadioButton{border-width:0px;}");
    grp1 = new QButtonGroup();
    grp1->addButton(r_isDesktop, 0);
    grp1->addButton(r_isNoDesktop, 1);
    //connect( grp1, SIGNAL(buttonClicked (int)), this, SLOT(button_desktop_Judge(int)));
    hIsD->addWidget(r_isDesktop);
    hIsD->addWidget(r_isNoDesktop);

    hIsD->setAlignment(r_isNoDesktop,Qt::AlignLeft);
    r_isNoDesktop->setFixedWidth(150);
    QLabel* is_patch = new QLabel("是否补丁：");
    is_patch->setStyleSheet("QLabel{border-width:0px;}");
    QHBoxLayout* hIsP = new QHBoxLayout();
    r_isPatch = new QRadioButton();
    r_isPatch->setText("是");
    r_isNoPatch = new QRadioButton();
    r_isNoPatch->setText("否");
    r_isPatch->setChecked(false);
    r_isNoPatch->setChecked(true);
    r_isPatch->setStyleSheet("QRadioButton{border-width:0px;}");
    r_isNoPatch->setStyleSheet("QRadioButton{border-width:0px;}");
    grp2 = new QButtonGroup();
    grp2->addButton(r_isPatch, 0);
    grp2->addButton(r_isNoPatch, 1);
    //connect( grp2, SIGNAL(buttonClicked (int)), this, SLOT(button_patch_Judge2(int)));

    hIsP->addWidget(r_isPatch);
    hIsP->addWidget(r_isNoPatch);
    hIsP->setAlignment(r_isNoPatch,Qt::AlignLeft);
    r_isNoPatch->setFixedWidth(150);
    QLabel* is_essential = new QLabel("是否系统必须：");
    is_essential->setStyleSheet("QLabel{border-width:0px;}");
    QHBoxLayout* hIsE = new QHBoxLayout();
    r_isEssential = new QRadioButton();
    r_isEssential->setText("是");
    r_isNoEssential = new QRadioButton();
    r_isNoEssential->setText("否");
    r_isEssential->setChecked(false);
    r_isNoEssential->setChecked(true);
    r_isEssential->setStyleSheet("QRadioButton{border-width:0px;}");
    r_isNoEssential->setStyleSheet("QRadioButton{border-width:0px;}");
    grp3 = new QButtonGroup();
    grp3->addButton(r_isEssential, 0);
    grp3->addButton(r_isNoEssential, 1);
    //connect( grp3, SIGNAL(buttonClicked (int)), this, SLOT(button_essential_Judge(int)));
    hIsE->addWidget(r_isEssential);
    hIsE->addWidget(r_isNoEssential);
    hIsE->setAlignment(r_isNoEssential,Qt::AlignLeft);
    r_isNoEssential->setFixedWidth(150);

    QLabel* lProtocol = new QLabel("开源协议：");
    lProtocol->setStyleSheet("QLabel{border-width:0px;}");
    sProtocol = new QComboBox();
    sProtocol->setFixedWidth(110);
    sProtocol->setFixedHeight(27);
    //    is_desktop->setFixedWidth(80);
    QString comb_text = QString("QComboBox::down-arrow {image: url(/usr/share/cpktransform/images/down.png);} "
                                "QComboBox::drop-down "
                                "{subcontrol-origin: "
                                "padding; subcontrol-position: top right; width: 20px;border-left-width: 1px;"
                                "border-left-color: darkgray;border-left-style: solid;"
                                "border-top-right-radius: 3px;"
                                " border-bottom-right-radius: 3px;}"
                                "QComboBox{background-color:rgb(255,255,240);"
                                "color:rgb(105,105,105);border-image:none; "
                                "border:1px solid gray; border-radius:2px};");
    sProtocol->setStyleSheet(comb_text);
    sProtocol->addItem("GPL");
    sProtocol->addItem("BSD");
    sProtocol->addItem("MIT");
    sProtocol->addItem("Distributable");
    sProtocol->addItem("Commercial");
    sProtocol->addItem("Share");
    sProtocol->addItem("其他");
    lprotocol = new QLineEdit();
    lprotocol->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    lprotocol->setFixedWidth(200);
    lprotocol->setFixedHeight(27);
    lprotocol->setText("GPL");
    //connect(sProtocol, SIGNAL(currentIndexChanged(int)), this, SLOT(process_Protocol(int)));

    QHBoxLayout* hbox_protocol = new QHBoxLayout();
    hbox_protocol->addWidget(lprotocol);
    hbox_protocol->addWidget(sProtocol);

    gbox_other->addWidget(is_desktop, 0,0,1,1);
    gbox_other->addLayout(hIsD,0,1,1,1);
    gbox_other->addWidget(is_patch, 1,0,1,1);
    gbox_other->addLayout(hIsP, 1,1,1,1);
    gbox_other->addWidget(is_essential, 2,0,1,1);
    gbox_other->addLayout(hIsE,2,1,1,1);
    gbox_other->addWidget(lProtocol, 3,0,1,1);
    gbox_other->addLayout(hbox_protocol,3,1,1,1);

    s_other= new QWidget;
    s_other->setFixedSize(470,150);
    s_other->setLayout(gbox_other);
    s_other->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:2px");//mencius

    QLabel* occupying_3 = new QLabel("");
    occupying_3->setFixedHeight(10);
    occupying_3->setStyleSheet("border:0px;");
    widget->addWidget(occupying_3,12,0,1,1);
    widget->addWidget(sother,13,0,1,1);
    widget->addWidget(s_other,14,0,1,1);
    widget->setAlignment(gbox_other,Qt::AlignLeft);
    //add end
}

#if 0
void Xml::button_desktop_Judge(int id)
{
    switch(id)
    {
    case 0:
    {
        r_isDesktop->setChecked(true);
        r_isNoDesktop->setChecked(false);
        break;
    }
    case 1:
    {
        r_isDesktop->setChecked(false);
        r_isNoDesktop->setChecked(true);
        break;
    }
    default:
        break;
    }
}

void Xml::button_patch_Judge(int id)
{
    switch(id)
    {
    case 0:
    {
        r_isPatch->setChecked(true);
        r_isNoPatch->setChecked(false);
        break;
    }
    case 1:
    {
        r_isPatch->setChecked(false);
        r_isNoPatch->setChecked(true);
        break;
    }
    default:
        break;
    }
}

void Xml::button_essential_Judge(int id)
{
    switch(id)
    {
    case 0:
    {
        r_isEssential->setChecked(true);
        r_isNoEssential->setChecked(false);
        break;
    }
    case 1:
    {
        r_isEssential->setChecked(false);
        r_isNoEssential->setChecked(true);
        break;
    }
    default:
        break;
    }
}

void Xml::process_Protocol(int index)
{
    switch(index)
    {
    case 0:
    {
        m_strLicense = "GPL";
        lprotocol->setText("GPL");
        break;
    }
    case 1:
    {
        m_strLicense = "BSD";
        lprotocol->setText("BSD");
        break;
    }
    case 2:
    {
        m_strLicense = "MIT";
        lprotocol->setText("MIT");
        break;
    }
    case 3:
    {
        m_strLicense = "Distributable";
        lprotocol->setText("Distributable");
        break;
    }
    case 4:
    {
        m_strLicense = "Commercial";
        lprotocol->setText("Commercial");
        break;
    }
    case 5:
    {
        m_strLicense = "Share";
        lprotocol->setText("Share");
        break;
    }
    case 6:
    {
        m_strLicense = "other";
        lprotocol->setText("");
        lprotocol->setPlaceholderText("输入协议名称");
        break;
    }
    default:
        break;
    }
}
#endif

//生成xml文件
void Xml::create_xml(QString filename)
{
    //预先生成CPK文件夹Mencius
    QString cpk_path = filename +"/CPK";
    QFileInfo fi(cpk_path.toLocal8Bit().data());
    if(fi.exists())
    {
        qDebug("exist CPK!\n");
        //return -1;
    }
    else
    {
        //创建文件夹
        if(mkdir(cpk_path.toLocal8Bit().data(), 00700) < 0)
        {
            printf("mkdir CPK error!\n");
            exit(1);
        }
    }
    QString fname = filename + "/CPK/control.xml";
    //检测control.xml文件是否存在
    QFileInfo fi_xml(fname);
    if(fi_xml.exists())
    {
        QString delete_xml = QString("rm %1").arg(fname);
        system(delete_xml.toLocal8Bit().data());
    }
    QFile file(fname);
    file.open(QIODevice::ReadWrite);
    //Dom文件
    QDomDocument doc;
    //Dom处理命令
    QDomProcessingInstruction instruction;
    instruction = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"GB2312\"");
    //添加子节点
    doc.appendChild(instruction);
    //Dom元素(根节点)
    QDomElement root = doc.createElement("CpkInfo");
    doc.appendChild(root);
    //QDomText text = doc.createTextNode("");
    //root.appendChild(text);

    QDomElement element_root = doc.createElement(tr("Software"));
    //Dom属性
    QDomAttr softname = doc.createAttribute(tr("name"));
    QDomElement element_id = doc.createElement(tr("id"));
    QDomElement element_genericname = doc.createElement(tr("genericname"));
    QDomElement genericname_keyword_en = doc.createElement(tr("keyword"));
    QDomElement genericname_keyword_zh = doc.createElement(tr("keyword"));
    QDomAttr genericname_type = doc.createAttribute("type");
    QDomAttr key_en_lang = doc.createAttribute("lang");
    QDomAttr key_zh_lang = doc.createAttribute("lang");
    QDomElement element_permission = doc.createElement(tr("permission"));
    QDomElement element_classification = doc.createElement(tr("classification"));
    QDomElement element_is_patch = doc.createElement(tr("is_patch"));
    QDomElement element_summary = doc.createElement(tr("summary"));
    QDomElement summary_keyword_en = doc.createElement(tr("keyword"));
    QDomElement summary_keyword_zh = doc.createElement(tr("keyword"));
    QDomElement element_description = doc.createElement(tr("description"));
    QDomElement description_keyword_en = doc.createElement(tr("keyword"));
    QDomElement description_keyword_zh = doc.createElement(tr("keyword"));
    QDomElement element_version = doc.createElement(tr("version"));
    QDomElement element_essential = doc.createElement(tr("essential"));
    QDomElement element_license = doc.createElement(tr("license"));
    QDomElement element_category= doc.createElement(tr("category"));
    QDomElement element_architecture = doc.createElement(tr("architecture"));
    QDomElement element_exec = doc.createElement(tr("exec"));
    QDomElement element_install = doc.createElement(tr("install"));
    QDomElement element_homepage = doc.createElement(tr("homepage"));
    QDomElement element_vendor = doc.createElement(tr("vendor"));
    QDomAttr vendor_type = doc.createAttribute("type");
    QDomElement vendor_name = doc.createElement(tr("name"));
    QDomElement vendor_telephone = doc.createElement(tr("telephone"));
    QDomElement vendor_email = doc.createElement(tr("email"));
    QDomElement vendor_url = doc.createElement(tr("url"));
    QDomElement vendor_description = doc.createElement(tr("description"));
    QDomElement vendor_description_keyword_en = doc.createElement(tr("keyword"));
    QDomElement vendor_description_keyword_zh = doc.createElement(tr("keyword"));
    QDomElement element_pkgs_count = doc.createElement(tr("pkgs_count"));
    QDomElement element_pkgs = doc.createElement(tr("pkgs"));
    QDomElement pkgs_dateline = doc.createElement(tr("dateline"));
    QDomElement pkgs_self_size = doc.createElement(tr("self_size"));
    QDomElement pkgs_inst_size = doc.createElement(tr("inst_size"));
    QDomElement pkgs_depends = doc.createElement(tr("depends"));
    QDomElement element_source = doc.createElement(tr("source"));
    if(r_isDesktop->isChecked())
    {
        genericname_type.setValue("desktop");
    }
    else
    {
        genericname_type.setValue("");//temporary
    }
    softname.setValue(sname_en->text());
    key_en_lang.setValue("en");
    key_zh_lang.setValue("zh");
    if(r_enterprise->isChecked())
        vendor_type.setValue("company");
    else
        vendor_type.setValue("personal");
    QDomText text;
    text =doc.createTextNode("");
    element_id.appendChild(text);
    text = doc.createTextNode("");
    element_genericname.appendChild(text);
    text = doc.createTextNode(sname_en->text());
    genericname_keyword_en.appendChild(text);
    text = doc.createTextNode(sname->text());
    genericname_keyword_zh.appendChild(text);

    QString strPermission = "";
    if(root_user->isChecked())
        strPermission.append("ccf.permission.USE_ROOT;");
    if(sudo_user->isChecked())
        strPermission.append("ccf.permission.USE_SUDO;");
    if(ipc_user->isChecked())
        strPermission.append("ccf.permission.USE_IPC;");
    if(s_n_access->isChecked())
        strPermission.append("ccf.permission.ACCESS_NETWORK_STATE;");
    if(network_access->isChecked())
        strPermission.append("ccf.permission.ACCESS_NETWORK;");
    if(xorg_access->isChecked())
        strPermission.append("ccf.permission.ACCESS_XORG;");
    if(manager_user->isChecked())
        strPermission.append("ccf.permission.USER_MANAGER;");
    if(m_g_user->isChecked())
        strPermission.append("ccf.permission.USER_GROUP_MANAGER;");
    if(variable_system->isChecked())
        strPermission.append("ccf.permission.SYSTEM_VARIABLE;");
    if(manager_device->isChecked())
        strPermission.append("ccf.permission.DEVICE_MANAGER;");
    if(m_i_open->isChecked())
        strPermission.append("ccf.permission.OPEN_INPUT_METHOD;");
    if(manager_app->isChecked())
        strPermission.append("ccf.permission.APP_MANAGER;");
    if(setting_system->isChecked())
        strPermission.append("ccf.permission.SYSTEM_SETTING;");
    if(conf_change->isChecked())
        strPermission.append("ccf.permission.CHANGE_CONFIGURATION;");
    if(c_a_c->isChecked())
        strPermission.append("ccf.permission.CLEAR_APP_CACHE;");
    if(d_u_a_c->isChecked())
        strPermission.append("ccf.permission.CLEAR_APP_USER_DATA;");
    if(underly_access->isChecked())
        strPermission.append("ccf.permission.ACCESS_UNDERLY;");
    if(f_c_d->isChecked())
        strPermission.append("ccf.permission.DELETE_CACHE_FILES;");
    if(diagnostic->isChecked())
        strPermission.append("ccf.permission.DIAGNOSTIC;");
    if(dump->isChecked())
        strPermission.append("ccf.permission.DUMP;");
    if(a_d_c->isChecked())
        strPermission.append("ccf.permission.CHANGE_DEFAULT_APP;");
    if(m_s_c->isChecked())
        strPermission.append("ccf.permission.CHANGE_START_MENU;");
    if(b_t_c->isChecked())
        strPermission.append("ccf.permission.CHANGE_TASK_BAR;");
    if(tasks_get->isChecked())
        strPermission.append("ccf.permission.GET_TASKS;");
    if(search_global->isChecked())
        strPermission.append("ccf.permission.GLOBAL_SEARCH;");
    if(p_b_k->isChecked())
        strPermission.append("ccf.permission.KILL_BACKGROUND_PROCESSES;");
    if(clear_master->isChecked())
        strPermission.append("ccf.permission.MASTER_CLEAR;");
    if(s_a_m->isChecked())
        strPermission.append("ccf.permission.MODIFY_AUDIO_SETTINGS;");
    if(f_f_m->isChecked())
        strPermission.append("ccf.permission.MOUNT_FORMAT_FILESYSTEMS;");
    if(f_u_m->isChecked())
        strPermission.append("ccf.permission.MOUNT_UNMOUNT_FILESYSTEMS;");
    if(b_f_r->isChecked())
        strPermission.append("ccf.permission.READ_FRAME_BUFFER;");
    if(s_i_r->isChecked())
        strPermission.append("ccf.permission.READ_INPUT_STATE;");
    if(logs_read->isChecked())
        strPermission.append("ccf.permission.READ_LOGS;");
    if(reboot->isChecked())
        strPermission.append("ccf.permission.REBOOT;");
    if(c_b_r->isChecked())
        strPermission.append("ccf.permission.RECEIVE_BOOT_COMPLETED;");
    if(l_p_s->isChecked())
        strPermission.append("ccf.permission.SET_PROCESS_LIMIT;");
    if(time_set->isChecked())
        strPermission.append("ccf.permission.SET_TIME;");
    if(z_t_s->isChecked())
        strPermission.append("ccf.permission.SET_TIME_ZONE;");
    if(credentials_use->isChecked())
        strPermission.append("ccf.permission.USE_CREDENTIALS;");
    if(h_b_c->isChecked())
        strPermission.append("com.ccf.browser.permission.CHANGE_BROWSER_HOME;");
    if(b_h_r->isChecked())
        strPermission.append("com.ccf.browser.permission.READ_HISTORY_BOOKMARKS;");
    if(b_h_w->isChecked())
        strPermission.append("com.ccf.browser.permission.WRITE_HISTORY_BOOKMARKS;");
    if(s_w_a->isChecked())
        strPermission.append("ccf.permission.ACCESS_WIFI_STATE;");
    if(s_w_c->isChecked())
        strPermission.append("ccf.permission.CHANGE_WIFI_STATE;");
    if(bluetooth->isChecked())
        strPermission.append("ccf.permission.USE_BLUETOOTH;");
    if(manager_bluetooth->isChecked())
        strPermission.append("ccf.permission.BLUETOOTH_MANAGER;");
    if(power_device->isChecked())
        strPermission.append("ccf.permission.DEVICE_POWER");
    text = doc.createTextNode(strPermission);
    element_permission.appendChild(text);

    switch(sdense->currentIndex())
    {
    case 0:
    {
        m_strDense = "L0";
        break;
    }
    case 1:
    {
        m_strDense = "L1";
        break;
    }
    case 2:
    {
        m_strDense = "L2";
        break;
    }
    case 3:
    {
        m_strDense = "L3";
        break;
    }
    case 4:
    {
        m_strDense = "other";
        break;
    }
    default:
        break;
    }
    text = doc.createTextNode(m_strDense);
    element_classification.appendChild(text);
    if(r_isPatch->isChecked() && !r_isNoPatch->isChecked())
    {
        text = doc.createTextNode("1");
    }
    else
    {
        text = doc.createTextNode("0");
    }
    element_is_patch.appendChild(text);
    text = doc.createTextNode("");
    element_summary.appendChild(text);
    text = doc.createTextNode(lsdesc_en->text());
    summary_keyword_en.appendChild(text);
    text = doc.createTextNode(lsdesc->text());
    summary_keyword_zh.appendChild(text);
    text = doc.createTextNode("");
    element_description.appendChild(text);
    text = doc.createTextNode(tldesc_en->toPlainText());
    description_keyword_en.appendChild(text);
    text = doc.createTextNode(tldesc->toPlainText());
    description_keyword_zh.appendChild(text);
    QString version = l_1->text() +"." +l_2->text()+"."+l_3->text();
    text = doc.createTextNode(version);
    element_version.appendChild(text);
    if(r_isEssential->isChecked() && !r_isNoEssential->isChecked())
    {
        text = doc.createTextNode("1");
    }
    else
    {
        text = doc.createTextNode("0");
    }
    element_essential.appendChild(text);

    text = doc.createTextNode(lprotocol->text());
    element_license.appendChild(text);
    switch(scategory->currentIndex())
    {
    case 0:
    {
        m_strCategory = "Office";
        break;
    }
    case 1:
    {
        m_strCategory = "Application";
        break;
    }
    case 2:
    {
        m_strCategory = "Network";
        break;
    }
    case 3:
    {
        m_strCategory = "IM";
        break;
    }
    case 4:
    {
        m_strCategory = "Graphics";
        break;
    }
    case 5:
    {
        m_strCategory = "Mutimedia";
        break;
    }
    case 6:
    {
        m_strCategory = "Security";
        break;
    }
    case 7:
    {
        m_strCategory = "System";
        break;
    }
    case 8:
    {
        m_strCategory = "Development";
        break;
    }
    case 9:
    {
        m_strCategory = "Other";
        break;
    }
    }
    text = doc.createTextNode(m_strCategory);
    element_category.appendChild(text);
    text = doc.createTextNode(larch->text());
    element_architecture.appendChild(text);
    text = doc.createTextNode(lExec->text());
    element_exec.appendChild(text);
    text = doc.createTextNode(sname_en->text() +".install");
    element_install.appendChild(text);
    text = doc.createTextNode(str_soft_hp);
    element_homepage.appendChild(text);
    text = doc.createTextNode("");
    element_vendor.appendChild(text);
    text = doc.createTextNode(l_name->text());
    vendor_name.appendChild(text);
    text = doc.createTextNode(l_tel->text());
    vendor_telephone.appendChild(text);
    text = doc.createTextNode(l_email->text());
    vendor_email.appendChild(text);
    text = doc.createTextNode(l_pg->text());
    vendor_url.appendChild(text);
    text = doc.createTextNode("");
    vendor_description.appendChild(text);
    text = doc.createTextNode(l_desc_en->text());
    vendor_description_keyword_en.appendChild(text);
    text = doc.createTextNode(l_desc->text());
    vendor_description_keyword_zh.appendChild(text);
    text = doc.createTextNode("");
    element_pkgs_count.appendChild(text);
    text = doc.createTextNode("");
    element_pkgs.appendChild(text);
    text = doc.createTextNode("");
    pkgs_dateline.appendChild(text);
    text = doc.createTextNode("");
    pkgs_self_size.appendChild(text);
    text = doc.createTextNode("");
    pkgs_inst_size.appendChild(text);
    switch(sdenpendence->currentIndex())
    {
    case 0:
    {
        m_strDepends = "ccf1 (>= 1.0.0)";
        break;
    }
    case 1:
    {
        m_strDepends = "ccf1 (>= 2.0.0)";
        break;
    }
    default:
        break;
    }
    text = doc.createTextNode(m_strDepends);
    pkgs_depends.appendChild(text);
    text = doc.createTextNode("");
    element_source.appendChild(text);

    text.clear();
    element_root.appendChild(element_id);
    element_root.appendChild(element_genericname);
    element_root.appendChild(element_permission);
    element_root.appendChild(element_classification);
    element_root.appendChild(element_is_patch);
    element_root.appendChild(element_summary);
    element_root.appendChild(element_description);
    element_root.appendChild(element_version);
    element_root.appendChild(element_essential);
    element_root.appendChild(element_license);
    element_root.appendChild(element_category);
    element_root.appendChild(element_architecture);
    element_root.appendChild(element_exec);
    element_root.appendChild(element_install);
    element_root.appendChild(element_homepage);
    element_root.appendChild(element_vendor);
    element_root.appendChild(element_pkgs_count);
    element_root.appendChild(element_pkgs);
    element_root.appendChild(element_source);
    element_root.setAttributeNode(softname);
    element_genericname.setAttributeNode(genericname_type);
    genericname_keyword_en.setAttributeNode(key_en_lang);
    genericname_keyword_zh.setAttributeNode(key_zh_lang);
    summary_keyword_en.setAttributeNode(key_en_lang);
    summary_keyword_zh.setAttributeNode(key_zh_lang);
    description_keyword_en.setAttributeNode(key_en_lang);
    description_keyword_zh.setAttributeNode(key_zh_lang);
    vendor_description_keyword_en.setAttributeNode(key_en_lang);
    vendor_description_keyword_zh.setAttributeNode(key_zh_lang);
    element_genericname.appendChild(genericname_keyword_en);
    element_genericname.appendChild(genericname_keyword_zh);
    element_summary.appendChild(summary_keyword_en);
    element_summary.appendChild(summary_keyword_zh);
    element_description.appendChild(description_keyword_en);
    element_description.appendChild(description_keyword_zh);
    element_vendor.setAttributeNode(vendor_type);
    element_vendor.appendChild(vendor_name);
    element_vendor.appendChild(vendor_telephone);
    element_vendor.appendChild(vendor_email);
    element_vendor.appendChild(vendor_url);
    element_vendor.appendChild(vendor_description);
    vendor_description.appendChild(vendor_description_keyword_en);
    vendor_description.appendChild(vendor_description_keyword_zh);
    element_pkgs.appendChild(pkgs_dateline);
    element_pkgs.appendChild(pkgs_self_size);
    element_pkgs.appendChild(pkgs_inst_size);
    element_pkgs.appendChild(pkgs_depends);
    root.appendChild(element_root);
    QTextStream out(&file);
    doc.save(out,4);
    file.close();
}

void Xml::delete_data()
{
    tldesc_en->clear();
    tldesc->clear();
    m_strCategory.clear();
    m_strDepends.clear();
    m_strDense.clear();
    m_strLicense.clear();
    sname->clear();
    sname_en->clear();
    scategory->setCurrentIndex(1);
    l_1->clear();
    l_2->clear();
    l_3->clear();
    lExec->clear();
    larch->clear();
    l_desc->clear();
    l_desc_en->clear();
    sdenpendence->setCurrentIndex(0);
    sdense->setCurrentIndex(0);
    lsdesc->clear();
    lsdesc_en->clear();
    root_user->setChecked(false);
    sudo_user->setChecked(false);
    ipc_user->setChecked(false);
    s_n_access->setChecked(false);
    network_access->setChecked(false);
    xorg_access->setChecked(false);
    manager_user->setChecked(false);
    m_g_user->setChecked(false);
    variable_system->setChecked(false);
    manager_device->setChecked(false);
    m_i_open->setChecked(false);
    manager_app->setChecked(false);
    setting_system->setChecked(false);
    conf_change->setChecked(false);
    c_a_c->setChecked(false);
    d_u_a_c->setChecked(false);
    underly_access->setChecked(false);
    f_c_d->setChecked(false);
    diagnostic->setChecked(false);
    dump->setChecked(false);
    a_d_c->setChecked(false);
    m_s_c->setChecked(false);
    b_t_c->setChecked(false);
    tasks_get->setChecked(false);
    search_global->setChecked(false);
    p_b_k ->setChecked(false);
    clear_master->setChecked(false);
    s_a_m->setChecked(false);
    f_f_m->setChecked(false);
    f_u_m->setChecked(false);
    b_f_r->setChecked(false);
    s_i_r->setChecked(false);
    logs_read->setChecked(false);
    reboot->setChecked(false);
    c_b_r->setChecked(false);
    l_p_s->setChecked(false);
    time_set->setChecked(false);
    z_t_s->setChecked(false);
    credentials_use->setChecked(false);
    h_b_c->setChecked(false);
    b_h_r->setChecked(false);
    b_h_w->setChecked(false);
    s_w_a->setChecked(false);
    s_w_c->setChecked(false);
    bluetooth->setChecked(false);
    manager_bluetooth->setChecked(false);
    power_device->setChecked(false);
    r_enterprise->setChecked(true);
    r_individual->setChecked(false);
    r_isDesktop->setChecked(true);
    r_isNoDesktop->setChecked(false);
    r_isPatch->setChecked(false);
    r_isNoPatch->setChecked(true);
    r_isEssential->setChecked(false);
    r_isNoEssential->setChecked(true);
    sProtocol->setCurrentIndex(0);
    lprotocol->setText("GPL");
}
